//
//  OnlineUserLogic.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/7/26.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "OnlineUserLogic.h"
#import "UserListInfo.h"

@implementation OnlineUserLogic

- (instancetype)init
{
    self = [super init];
    if (self) {
        _page = 0;
        _dataArray = [NSMutableArray array];
    }
    return self;
}

-(void)loadData
{
    if (_page == 0) {
        [_dataArray removeAllObjects];
    }
    
    //默认是在线用户
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"page_data_api" A:@"request_get_index_online"];
    if(self.type == HomePageListTypeFollow)
    {
        url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"page_data_api" A:@"request_get_follow_emcee_list"];
    }
    else if(self.type == HomePageListTypeNew)
    {
        
    }
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@(_page) forKey:@"page"];
    
    [CYNET POSTv3:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        if (_page == 1) {
            [_dataArray removeAllObjects];
        }
        NSArray *list = [NSArray modelArrayWithClass:[UserListInfo class] json:[responseObject valueForKey:@"data"]];
        [_dataArray addObjectsFromArray:list];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } failure:^(NSString *error, NSInteger code) {
        [[HUDHelper sharedInstance] tipMessage:error];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } hasCache:YES];
}
@end
